<!doctype html>
<html>

	<head>
		<meta charset="UTF-8">
		<title></title>
		<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		<link href="../css/mui.min.css" rel="stylesheet" />
		<link rel="stylesheet" href="css/index.css" />
		<link rel="stylesheet" href="css/login.css" />
	</head>
	<body>
		<header class="mui-bar mui-bar-nav">
		    <a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left"></a>
		    <h1 class="mui-title">CMR登陆</h1>
		</header>
		<div class="mui-content">
			<div class="mui-content-padded">
				<div class="login-input">
					<div class="input-box">
						<img src="img/user_1.png"/>
						<input type="text" placeholder="请输入CRM账号" id="user" />
					</div>
					<div class="input-box">
						<img src="img/pasw.png"/>
						<input type="password" placeholder="请输入CRM密码" id="pasw" />
					</div>
					<div class="input-box">
						<a href="javascript:void(0)" id="login">登录</a>
					</div>
				</div>
			</div>
		</div>
		<script src="../js/mui.min.js"></script>
		<script type="text/javascript" src="../js/evalHttp.js" ></script>
		<script type="text/javascript">
			mui.init()
		</script>
		<script type="text/javascript">
			mui.ready(function(){
				Xeval.setUrl("http://192.168.191.1/");
				var user = localStorage.getItem("art_user");
				if(user){
					try{
						var juser = JSON.parse(user);
						mui("#user")[0].value = juser.data.T_accountnumber;
					}catch(e){
						
					}
				}
				mui('.input-box').on("tap","#login",function(){
					var params = {
						name:mui("#user")[0].value,
						pwd:mui("#pasw")[0].value
					}
					Xeval.Http(Xeval.Mode.HTTP_ART_POST_LOGIN,params,cb);
					function cb(isOk,data){
						console.log(JSON.stringify(data))
						if(isOk){
							mui.toast(data.msg);
							if(data.state==1 || data.state==2){
								mui("#pasw")[0].value = "";
								localStorage.setItem("art_user",JSON.stringify(data));
								/*
								 * 更改一下主页面的guid！,保证退出crm后，不影响其他功能。
								 *                  <---不背锅！
								 * */
								var userinfo = localStorage.getItem("userinfo");
								if(userinfo){
									try{
										var indexUser = JSON.parse(userinfo);
										if(indexUser.user == data.data.T_accountnumber){
											indexUser.guid = data.guid;
											localStorage.setItem("userinfo",JSON.stringify(indexUser));
										}
									}catch(e){
										
									}
								}
								mui.openWindow({
									url:"index.html",
									id:"artisan_index.html"
								})
							}
						}else{
							mui.alert("网络错误，请检查您的网络情况")
						}
					}
				})
			})
			
		</script>
	</body>

</html>